#include <irrlicht.h>

using namespace irr;
using namespace core;
using namespace video;

enum PLAYER {LEFT_PLAYER, RIGHT_PLAYER};

const u8 SHASSIS_POS_X = 41; //px
const u8 SHASSIS_POS_Y = 41; //px
const u8 CENTER_OF_MASS_POS_X = 42; //px
const u8 CENTER_OF_MASS_POS_Y = 26; //px
const u8 AIRPLANE_HEIGHT = 8;

class World;
class KeyboardEventsReceiver;

const f32 SPEED_AT_LIFTOFF = .7f; // pixels/milliseconds
const f32 SPEED_AT_LIFTOFF_TAIL = .5f; // pixels/milliseconds

const f32 SPEED_MAX = 0.7f; // pixels/milliseconds
const f32 SPEED_MIN = 0.0f;
const f32 AIRPLANE_ACCELERATION = 0.001f; //pixels/milliseconds^2
const f32 ANGLE_ACCELERATION = .2f;	 //degrees/milliseconds^2

const f32 AIRPLANE_RATE_OF_GUN = 200.0f; //in millisecond
const f32 AIRPLANE_ACCURACY_OF_GUN = 5.0f;//+-degrees

const s8 ANIMATION_ENDED = -1;

class Airplane
{
	u32 liftoffTime; //time in millisecond when aircraft tail liftoff
	u32 crashTime; //time in millisecond when aircraft crash
	u32 fireTime;//time in millisecond when pressed FIRE Key
	gui::IGUIStaticText* info; //only for debug

	array<vector2di> drawingVectors; //only for DEBUG

	World* world;

	PLAYER playerSide;

	f32 speed;// px/frame
	f32 angle;
	u8 angleChangeVelocity;//increate if A or D pressed
	position2df pos;//position of airoplane in world

	vector2df prevMoving;

	bool onGround;
	bool airplaneCrash;
	s8 bangFrame; //bang animation, if -1 them airplane crashed and animation ended
	s8 bangFrameCount;

	IVideoDriver* driver;
	ITexture* leftAirplaneImage;
	
	ITexture* bangImage;

public:
	Airplane(PLAYER side, World* _world);

	void ProcessKeyboardEvents(KeyboardEventsReceiver* receiver);
	void AirplaneFlying();

	//draw airplane
	void Draw();

	bool IsAirplaneOnGround();
};